/*
    This file is part of Raptor.

    Raptor is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Raptor is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Raptor.  If not, see <http://www.gnu.org/licenses/>.

 */

#ifndef PLUGINHOSTER_H
#define PLUGINHOSTER_H

#include "interfaceHoster.h"
#include "exceptions.h"

#include <QObject>
#include <QPluginLoader>
#include <QDebug>
#include <QFile>
#include <QPointer>
#include <QRegExp>

class PluginHoster : public QObject
{
    Q_OBJECT

    public:
        enum E_ERRORS
        {
            ERROR_PLUGIN
        };

        PluginHoster(QString const& lib);
        ~PluginHoster();

        QPair<InterfaceHoster*, QObject* > createHosterObj();
        //void destroyHosterObj(InterfaceHoster*);

        bool isValidHoster(QString const& host);

        bool loaded() const { return _loaded; };

        InterfaceHoster::S_INFO const info() const { return _info; };


        void setMode(InterfaceHoster::E_MODE const& mode) { _info.mode = mode; };
        void setMaxDownloads(int const& count) { _info.maxDownloads = count; };

        bool canStartDl(InterfaceHoster::E_MODE const& mode);
        void incDownloads(InterfaceHoster::E_MODE const& mode);
        void decDownloads(InterfaceHoster::E_MODE const& mode);

    signals:
        void error(PluginHoster::E_ERRORS const &error);

    private:
        QPluginLoader *pluginLoader;
        InterfaceHoster *hosterInterface;
        QObject *hosterObject;

        QString pluginFile;

        bool _loaded;

        InterfaceHoster::S_INFO _info;
};

#endif // PLUGINHOSTER_H
